import { Behaviour, getGameObjectById, Transform, core } from "./gameengine";
import { ColliderSystem } from "./rect/ColliderSystem";
import { RectCollider, RectColliderType } from "./rect/RectCollider";
import { MarshalStartState, marshal, MarshalSecondState, MarshalFirstState, MarshalThirdState, MarshalFourthState, MarshalFifthState, MarshalSixthState, MarshalSeventhState } from "./Marshal";
import { user } from "./user";


export class TP extends Behaviour {


    // private speedX = 0;
    // private speedY = 0;


    protected onStart() {
    }

    protected onUpdate(advancedTime: number) {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        const collider = this.displayObject.getScript(RectCollider);

        const nextCollider = {
            left: collider.left + -4,
            right: collider.right + 4,
            top: collider.top + -4,
            bottom: collider.bottom + 4
        }
        const hitTestResult1 = colliderSystem.check(nextCollider, RectColliderType.MAINROLE);
        if (hitTestResult1) {
            if (this.displayObject.id == "firstIn") {
                marshal.changeState(new MarshalFirstState());

            }
            if (this.displayObject.id == "firstOut") {
                user.nextEntryPositonX = 832;
                user.nextEntryPositonY = 64;
                // const mainrole = getGameObjectById("MainRole").getScript(Transform);
                // console.log(mainrole.x)
                // mainrole.x = 0;
                // mainrole.y = 0;

                marshal.changeState(new MarshalSecondState());
            }
            if (this.displayObject.id == "SecondIn") {
                user.nextEntryPositonX = 768;
                user.nextEntryPositonY = 704;
                marshal.changeState(new MarshalFirstState());
                // const mainrole = getGameObjectById("MainRole").getScript(Transform);
                // console.log(mainrole.x)
                // mainrole.x = 0;
                // mainrole.y = 0;
            }
            if (this.displayObject.id == "SecondOut") {
                user.nextEntryPositonX = 448;
                user.nextEntryPositonY = 384;
                // user.nextEntryPositon = 222;
                marshal.changeState(new MarshalThirdState());
            }
            if (this.displayObject.id == "ThirdIn") {
                user.nextEntryPositonX = 1088;
                user.nextEntryPositonY = 384;
                marshal.changeState(new MarshalSecondState());
            }
            if (this.displayObject.id == "ThirdOut") {
                user.nextEntryPositonX = 448;
                user.nextEntryPositonY = 384;
                marshal.changeState(new MarshalFourthState());
            }
            if (this.displayObject.id == "FourthIn") {
                user.nextEntryPositonX = 1088;
                user.nextEntryPositonY = 384;
                marshal.changeState(new MarshalThirdState());
            }
            if (this.displayObject.id == "FourthOut") {
                user.nextEntryPositonX = 768;
                user.nextEntryPositonY = 704;
                marshal.changeState(new MarshalFifthState());
            }
            if (this.displayObject.id == "FifthIn") {
                user.nextEntryPositonX = 768;
                user.nextEntryPositonY = 65;
                marshal.changeState(new MarshalFourthState());
            }
            if (this.displayObject.id == "FifthOut") {
                user.nextEntryPositonX = 448;
                user.nextEntryPositonY = 64;
                marshal.changeState(new MarshalSixthState());
            }
            if (this.displayObject.id == "SixthIn") {
                user.nextEntryPositonX = 1088;
                user.nextEntryPositonY = 64;
                marshal.changeState(new MarshalFifthState());
            }
            if (this.displayObject.id == "SixthOut") {
                user.nextEntryPositonX = 896;
                user.nextEntryPositonY = 64;
                marshal.changeState(new MarshalSeventhState());
            }
            if (this.displayObject.id == "SeventhIn") {
                user.nextEntryPositonX = 960;
                user.nextEntryPositonY = 704;
                marshal.changeState(new MarshalSixthState());
            }
            if (this.displayObject.id == "SeventhOut") {
                marshal.changeState(new MarshalStartState());
            }


        }

    }


}